package ControlLayer;

import ModelLayer.*;
/**
 * Loan Controller layer will handle a loan, a copy and a address person
 * 
 * @author (Bo Nielsen) 
 * @version (V.1)
 */
public class LoanCtr
{
    private DVDCtr copy;
    private AddressCtr address;
    private LoanContainer loanCon;

    public LoanCtr()
    {
        copy = new DVDCtr();
        address = new AddressCtr();
        loanCon = LoanContainer.getInstance();
    }

    //Create loan
    public void createLoan(long id, String bd, String per, String state, long copySn, long perId )
    {
        Copy c = copy.findCopy(copySn);
        Person p = address.findPerson(perId);

        if(c.getIsLentOut() == false){
            c.setIsLentOut(true);
            Loan l = new Loan(id, bd, per, state, c, p);
            loanCon.addLoan(l);

        }else{
            System.out.println("Copy is lent out!");

        }
    }
    //find loan
    public Loan findLoan(long id)
    {
        return loanCon.getLoan(id);
    }
    //delete Loan
    public void deleteLoan(long id)
    {
        
        loanCon.deleteLoan(id);
    }
    //List all loans
    public void listAllLoans()
    {
        loanCon.listAllLoans();
    }

}
